package com.zero365.autobak.ui;

import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.swt.widgets.Group;
import org.eclipse.swt.SWT;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Combo;
import org.eclipse.swt.widgets.DirectoryDialog;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Text;
import org.eclipse.swt.events.SelectionAdapter;
import org.eclipse.swt.events.SelectionEvent;

public class MainWin {

	protected Shell shell;
	private Text backuppath;
	private Text text;
	private Text text_1;
	private Text text_3;
	private Text text_4;
	private Text text_5;
	private Text text_2;
	private Text text_6;
	private Text text_7;
	private Text text_8;
	private Text text_9;

	/**
	 * Launch the application.
	 * @param args
	 */
	public static void main(String[] args) {
		try {
			MainWin window = new MainWin();
			window.open();
		} catch (Exception e) {
			e.printStackTrace();
		}
	}

	/**
	 * Open the window.
	 */
	public void open() {
		Display display = Display.getDefault();
		createContents();
		shell.open();
		shell.layout();
		while (!shell.isDisposed()) {
			if (!display.readAndDispatch()) {
				display.sleep();
			}
		}
	}

	/**
	 * Create contents of the window.
	 */
	protected void createContents() {
		shell = new Shell();
		shell.setSize(559, 636);
		shell.setText("SWT Application");
		
		Group group = new Group(shell, SWT.NONE);
		group.setText("备份时间");
		group.setBounds(10, 10, 522, 156);
		
		Button button = new Button(group, SWT.RADIO);
		button.setSelection(true);
		button.setBounds(25, 23, 45, 17);
		button.setText("每天");
		
		Button button_1 = new Button(group, SWT.RADIO);
		button_1.setBounds(206, 23, 57, 17);
		button_1.setText("每周");
		
		Combo combo = new Combo(group, SWT.NONE);
		combo.setItems(new String[] {"0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "11", "12", "13", "14", "15", "16", "17", "18", "19", "20", "21", "22", "23"});
		combo.setBounds(46, 46, 88, 25);
		combo.select(12);
		
		Combo combo_1 = new Combo(group, SWT.NONE);
		combo_1.setItems(new String[] {"00", "01", "02", "03", "04", "05", "06", "07", "08", "09", "10", "11", "12", "13", "14", "15", "16", "17", "18", "19", "20", "21", "22", "23", "24", "25", "26", "27", "28", "29", "30", "31", "32", "33", "34", "35", "36", "37", "38", "39", "40", "41", "42", "43", "44", "45", "46", "47", "48", "49", "50", "51", "52", "53", "54", "55", "56", "57", "58", "59"});
		combo_1.setBounds(46, 78, 88, 25);
		combo_1.select(0);
		
		Label label = new Label(group, SWT.NONE);
		label.setBounds(25, 49, 15, 17);
		label.setText("时:");
		
		Label label_1 = new Label(group, SWT.NONE);
		label_1.setBounds(25, 81, 15, 17);
		label_1.setText("分:");
		
		Button button_2 = new Button(group, SWT.CHECK);
		button_2.setBounds(206, 46, 57, 17);
		button_2.setText("星期六");
		
		Button button_3 = new Button(group, SWT.CHECK);
		button_3.setText("星期日");
		button_3.setBounds(269, 46, 57, 17);
		
		Button button_4 = new Button(group, SWT.CHECK);
		button_4.setText("星期一");
		button_4.setBounds(206, 78, 57, 17);
		
		Button button_5 = new Button(group, SWT.CHECK);
		button_5.setText("星期二");
		button_5.setBounds(269, 78, 57, 17);
		
		Button button_6 = new Button(group, SWT.CHECK);
		button_6.setText("星期三");
		button_6.setBounds(333, 78, 57, 17);
		
		Button button_7 = new Button(group, SWT.CHECK);
		button_7.setText("星期四");
		button_7.setBounds(397, 78, 57, 17);
		
		Button button_8 = new Button(group, SWT.CHECK);
		button_8.setSelection(true);
		button_8.setText("星期五");
		button_8.setBounds(462, 78, 57, 17);
		
		Label label_2 = new Label(group, SWT.NONE);
		label_2.setBounds(22, 126, 68, 17);
		label_2.setText("备份文件夹:");
		
		backuppath = new Text(group, SWT.BORDER);
		backuppath.setBounds(93, 123, 340, 23);
		
		Button selectdir = new Button(group, SWT.NONE);
		selectdir.addSelectionListener(new SelectionAdapter() {
			@Override
			public void widgetSelected(SelectionEvent e) {
				folderDig(shell);
			}
		});
		selectdir.setBounds(439, 120, 73, 27);
		selectdir.setText("选择文件夹");
		
		Group group_1 = new Group(shell, SWT.NONE);
		group_1.setText("本地备份");
		group_1.setBounds(10, 172, 522, 59);
		
		Button button_9 = new Button(group_1, SWT.CHECK);
		button_9.setBounds(10, 27, 73, 17);
		button_9.setText("本地备份");
		
		text = new Text(group_1, SWT.BORDER);
		text.setBounds(88, 24, 291, 23);
		
		Button button_10 = new Button(group_1, SWT.NONE);
		button_10.setText("选择文件夹");
		button_10.setBounds(385, 22, 73, 27);
		
		Button button_15 = new Button(group_1, SWT.NONE);
		button_15.setBounds(464, 22, 48, 27);
		button_15.setText("确定");
		
		Group group_2 = new Group(shell, SWT.NONE);
		group_2.setText("网上邻居备份");
		group_2.setBounds(10, 237, 522, 173);
		
		Button button_11 = new Button(group_2, SWT.CHECK);
		button_11.setText("网上邻居备份");
		button_11.setBounds(10, 27, 93, 17);
		
		text_1 = new Text(group_2, SWT.BORDER);
		text_1.setBounds(77, 50, 167, 23);
		
		Button button_12 = new Button(group_2, SWT.NONE);
		button_12.setText("确定");
		button_12.setBounds(439, 138, 73, 27);
		
		Label lblIp = new Label(group_2, SWT.NONE);
		lblIp.setBounds(10, 58, 38, 17);
		lblIp.setText("IP地址:");
		
		text_3 = new Text(group_2, SWT.BORDER);
		text_3.setBounds(77, 79, 216, 23);
		
		Label label_3 = new Label(group_2, SWT.NONE);
		label_3.setBounds(10, 85, 61, 17);
		label_3.setText("远程路径:");
		
		text_4 = new Text(group_2, SWT.BORDER);
		text_4.setBounds(77, 113, 124, 23);
		
		text_5 = new Text(group_2, SWT.BORDER);
		text_5.setBounds(77, 140, 124, 23);
		
		Label label_4 = new Label(group_2, SWT.NONE);
		label_4.setBounds(10, 119, 45, 17);
		label_4.setText("用户名:");
		
		Label label_5 = new Label(group_2, SWT.NONE);
		label_5.setBounds(10, 146, 61, 17);
		label_5.setText("密码:");
		
		Group grpFtp = new Group(shell, SWT.NONE);
		grpFtp.setText("FTP备份");
		grpFtp.setBounds(10, 416, 522, 173);
		
		Button btnFtp = new Button(grpFtp, SWT.CHECK);
		btnFtp.setText("FTP备份");
		btnFtp.setBounds(10, 27, 93, 17);
		
		text_2 = new Text(grpFtp, SWT.BORDER);
		text_2.setBounds(77, 50, 167, 23);
		
		Button button_14 = new Button(grpFtp, SWT.NONE);
		button_14.setText("确定");
		button_14.setBounds(439, 138, 73, 27);
		
		Label label_6 = new Label(grpFtp, SWT.NONE);
		label_6.setText("IP地址:");
		label_6.setBounds(10, 58, 38, 17);
		
		text_6 = new Text(grpFtp, SWT.BORDER);
		text_6.setBounds(77, 79, 216, 23);
		
		Label label_7 = new Label(grpFtp, SWT.NONE);
		label_7.setText("远程路径:");
		label_7.setBounds(10, 85, 61, 17);
		
		text_7 = new Text(grpFtp, SWT.BORDER);
		text_7.setBounds(77, 113, 124, 23);
		
		text_8 = new Text(grpFtp, SWT.BORDER);
		text_8.setBounds(77, 140, 124, 23);
		
		Label label_8 = new Label(grpFtp, SWT.NONE);
		label_8.setText("用户名:");
		label_8.setBounds(10, 119, 45, 17);
		
		Label label_9 = new Label(grpFtp, SWT.NONE);
		label_9.setText("密码:");
		label_9.setBounds(10, 146, 61, 17);
		
		text_9 = new Text(grpFtp, SWT.BORDER);
		text_9.setText("21");
		text_9.setBounds(320, 50, 73, 23);
		
		Label label_10 = new Label(grpFtp, SWT.NONE);
		label_10.setBounds(274, 53, 40, 17);
		label_10.setText("端口:");

	}
	protected void folderDig(Shell parent){
		//新建文件夹（目录）对话框
		DirectoryDialog folderdlg=new DirectoryDialog(parent);
		//设置文件对话框的标题
		folderdlg.setText("文件选择");
		//设置初始路径
		folderdlg.setFilterPath("SystemDrive");
		//设置对话框提示文本信息
		folderdlg.setMessage("请选择相应的文件夹");
		//打开文件对话框，返回选中文件夹目录
		String selecteddir=folderdlg.open();
			if(selecteddir==null){
				return ;
			}
			else{
				backuppath.setText(selecteddir);
				//System.out.println("您选中的文件夹目录为："+selecteddir);
			}
		}
}
